home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dev / sun3.md / devInit.c < prev    next >
C/C++ Source or Header  |  1990-12-07  |  7KB  |  258 lines

  1. /*
  2.  * devInit.c --
  3.  *
  4.  *    This has a weak form of autoconfiguration for mapping in various
  5.  *    devices and calling their initialization routines.  The file
  6.  *    devConfig.c has the tables which list devices, their physical
  7.  *    addresses, and their initialization routines.
  8.  *
  9.  *    The Sun Memory Managment setup is explained in the proprietary
  10.  *    architecture documents, and also in the manual entitled
  11.  *    "Writing Device Drivers for the Sun Workstation"
  12.  *
  13.  *
  14.  * Copyright 1985, 1989 Regents of the University of California
  15.  * Permission to use, copy, modify, and distribute this
  16.  * software and its documentation for any purpose and without
  17.  * fee is hereby granted, provided that the above copyright
  18.  * notice appear in all copies.  The University of California
  19.  * makes no representations about the suitability of this
  20.  * software for any purpose.  It is provided "as is" without
  21.  * express or implied warranty.
  22.  */
  23.  
  24. #ifndef lint
  25. static char rcsid[] = "$Header: /sprite/src/kernel/dev/sun3.md/RCS/devInit.c,v 9.4 90/12/07 12:52:19 mgbaker Exp $ SPRITE (Berkeley)";
  26. #endif not lint
  27.  
  28. #include "sprite.h"
  29. #include "stdio.h"
  30. #include "devInt.h"
  31. #include "devMultibus.h"
  32. #include "vm.h"
  33. #include "vmMach.h"
  34. #include "dbg.h"
  35. #include "string.h"
  36. #include "ttyAttach.h"
  37. #ifdef sun4c
  38. #include "machMon.h"
  39. #endif
  40.  
  41. int devConfigDebug = FALSE;
  42.  
  43. /*
  44.  * ----------------------------------------------------------------------------
  45.  *
  46.  * Dev_Init --
  47.  *
  48.  *    Device initialization.
  49.  *
  50.  * Results:
  51.  *    None
  52.  *
  53.  * Side effects:
  54.  *    Set up interrupt routine for built-in UART interrupts.
  55.  *
  56.  * ----------------------------------------------------------------------------
  57.  */
  58.  
  59. void
  60. Dev_Init()
  61. {
  62.     DevTtyInit();
  63. }
  64.  
  65.  
  66. /*
  67.  *----------------------------------------------------------------------
  68.  *
  69.  * Dev_Config --
  70.  *
  71.  *    Call the initialization routines for various controllers and
  72.  *    devices based on configuration tables.  This should be called
  73.  *    after the regular memory allocater is set up so the drivers
  74.  *    can use it to configure themselves.
  75.  *
  76.  * Results:
  77.  *    None.
  78.  *
  79.  * Side effects:
  80.  *    Call the controller and device initialization routines.
  81.  *
  82.  *----------------------------------------------------------------------
  83.  */
  84. void
  85. Dev_Config()
  86. {
  87.     register int index;
  88.     int memoryType = 0;        /* This is ultimatly for the page table
  89.                  * type field used to map in the device */
  90.     Boolean mapItIn = FALSE;    /* If TRUE we need to map the device into
  91.                  * kernel virtual space */
  92.  
  93.     if (devConfigDebug) {
  94.     printf("Dev_Config calling debugger:");
  95.     DBG_CALL;
  96.     }
  97.     for (index = 0 ; index < devNumConfigCntrlrs ; index++) {
  98.     register DevConfigController *cntrlrPtr;
  99.     cntrlrPtr = &devCntrlr[index];
  100.     /*
  101.      * The following makes sure that the physical address for the
  102.      * controller is correct, and then maps that into the kernel's virtual
  103.      * address space (if it hasn't already been done by the Boot PROM).
  104.      * There are two things happening here.  First, each device has
  105.      * its own physical address on its own kind of bus - A device may
  106.      * think it's in Multibus Memory, or VME bus 16 bit data 16 bit address,
  107.      * or some other permutation.  For Multibus Memory devices, like
  108.      * the SCSI controller, Multibus memory is the low megabyte of
  109.      * the physical addresses, with Multibus I/O being the last 64K
  110.      * of this first Meg.  Furthermore, the Boot PROM maps this low
  111.      * meg of physical memory into the 16'th Meg of the kernel's virtual
  112.      * address space.  All that needs to be done is imitate this mapping
  113.      * by adding the MULTIBUS BASE to the controller address and the
  114.      * controller can forge ahead.
  115.      * It's more complicated for VME devices.  There are six subsets
  116.      * of address/data spaces supported by the VME bus, and each one
  117.      * belongs to a special range of physical addresses and has a
  118.      * corresponding "page type" which goes into the page table.
  119.      * Furthermore, we arn't depending on the boot PROM and so once
  120.      * the correct physical address is gen'ed up we need to map it
  121.      * into a kernel virtual address that the device driver can use.
  122.      */
  123.     if (Mach_GetMachineType() == SYS_SUN_2_120 &&
  124.         cntrlrPtr->space != DEV_MULTIBUS &&
  125.         cntrlrPtr->space != DEV_MULTIBUS_IO) {
  126.         /*
  127.          * Mapping VME addresses into a multibus based kernel
  128.          * messes things up.
  129.          */
  130.         continue;
  131.     }
  132.     switch(cntrlrPtr->space) {
  133.         case DEV_MULTIBUS:
  134.         case DEV_MULTIBUS_IO:
  135.         /*
  136.          * Things are already mapped in by the Boot PROM.
  137.          * We just relocate the address into the high meg.
  138.          */
  139.         if (Mach_GetMachineType() != SYS_SUN_2_120) {
  140.             continue;
  141.         }
  142.         mapItIn = FALSE;
  143.         cntrlrPtr->address += DEV_MULTIBUS_BASE;
  144.         break;
  145.         /*
  146.          * We have to relocate the controller address to the
  147.          * true VME PHYSICAL address that the Sun MMU uses for
  148.          * the different types of VME spaces.
  149.          */
  150.         case DEV_VME_D32A16:
  151.         case DEV_VME_D16A16:
  152.         /*
  153.          * The high 64K of the VME address range is stolen for the
  154.          * 16 bit address subset.
  155.          */
  156.         mapItIn = TRUE;
  157.         cntrlrPtr->address += 0xFFFF0000;
  158.         break;
  159.         case DEV_VME_D32A24:
  160.         case DEV_VME_D16A24:
  161.         /*
  162.          * The high 16 Megabytes of the VME address range is stolen
  163.          * for the 24 bit address subset.
  164.          */
  165.         mapItIn = TRUE;
  166.         cntrlrPtr->address += 0xFF000000;
  167.         break;
  168.         /*
  169.          * The addresses for the full 32 bit VME bus are ok.
  170.          */
  171.         case DEV_VME_D16A32:
  172.         case DEV_VME_D32A32:
  173.         mapItIn = TRUE;
  174.         break;
  175.         case DEV_OBIO:
  176.         mapItIn = FALSE;
  177.         break;
  178.         case DEV_SBUS_OB:
  179.         if (devConfigDebug) {
  180.             printf("Dev config looking at DEV_SBUS_OB.\n");
  181.         }
  182.         mapItIn = TRUE;
  183.         break;
  184.         case DEV_SBUS:
  185.         printf("Regular SBUS devices not handled yet.\n");
  186.         continue;
  187.     }
  188.     /*
  189.      * Each different Sun architecture arranges pieces of memory into
  190.      * 4 different spaces.  The I/O devices fall into type 2 or 3 space.
  191.      */
  192.     switch(cntrlrPtr->space) {
  193.         case DEV_MULTIBUS:
  194.         memoryType = 2;
  195.         break;
  196.         case DEV_VME_D16A16:
  197.         case DEV_VME_D16A24:
  198.         case DEV_VME_D16A32:
  199.         if (Mach_GetMachineType() == SYS_SUN_2_50) {
  200.             if (cntrlrPtr->address >= 0xFF800000) {
  201.             memoryType = 3;
  202.             } else {
  203.             memoryType = 2;
  204.             }
  205.         } else {
  206.             memoryType = 2;
  207.         }
  208.         break;
  209.         case DEV_MULTIBUS_IO:
  210.         case DEV_VME_D32A16:
  211.         case DEV_VME_D32A24:
  212.         case DEV_VME_D32A32:
  213.         memoryType = 3;
  214.         break;
  215.         case DEV_OBIO:
  216.         memoryType = 1;
  217.         break;
  218.         case DEV_SBUS_OB:
  219.         if (devConfigDebug) {
  220.             printf("Dev config setting mem type for DEV_SBUS_OB.\n");
  221.         }
  222.         memoryType = 1;
  223.         break;
  224.         case DEV_SBUS:
  225.         /* Regular SBUS devices not handled yet. */
  226.         continue;
  227.     }
  228.     if (mapItIn) {
  229.         if (devConfigDebug) {
  230.         printf("Dev config mapping %s at 0x%x, memType %d.\n",
  231.             cntrlrPtr->name, cntrlrPtr->address, memoryType);
  232.         }
  233.         cntrlrPtr->address =
  234.             (int) VmMach_MapInDevice((Address) cntrlrPtr->address,
  235.             memoryType);
  236.         if (devConfigDebug) { printf("Dev config virtual addr is 0x%x.\n",
  237.             cntrlrPtr->address);
  238.         }
  239.     }
  240.     if (cntrlrPtr->address != NIL) {
  241.         ClientData    callBackData;
  242.  
  243.         if (cntrlrPtr->initProc != (ClientData (*)()) NIL) {
  244.         callBackData = (*cntrlrPtr->initProc)(cntrlrPtr);
  245.         if (callBackData != DEV_NO_CONTROLLER) {
  246.             printf("%s at kernel address %x\n", cntrlrPtr->name,
  247.                    cntrlrPtr->address);
  248.             if (cntrlrPtr->vectorNumber > 0) {
  249.             Mach_SetHandler(cntrlrPtr->vectorNumber,
  250.                 cntrlrPtr->intrProc, callBackData);
  251.             }
  252.         }
  253.         }
  254.     }
  255.     }
  256.     return;
  257. }
  258.